import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserModule } from './user/user.mudule';
import { ConfigModule } from '@nestjs/config';
import configuration from './config/configuration';
import databaseConfig from './config/database.config';
import { ScheduleModule } from '@nestjs/schedule';
import { TasksModule } from './tasks/tasks.module';
import { EventEmitterModule, OnEvent } from '@nestjs/event-emitter';
import { LoggerMiddleware } from './middlewares/logger.middleware';
import { reqMiddleware } from './middlewares/func.middleware';
import { AllExceptionsFilter } from './filters/http-exception.filter';
import { APP_FILTER } from '@nestjs/core';
@Module({
    imports: [
        // 使用配置模块
        ConfigModule.forRoot({
            envFilePath: ['.env', '.env.local'],
            load: [configuration, databaseConfig],
        }),
        ScheduleModule.forRoot(),
        UserModule,
        // TasksModule,
        EventEmitterModule.forRoot(),
    ],
    controllers: [AppController],
    providers: [AppService,
        // {
        //     provide: APP_FILTER,
        //     useClass: AllExceptionsFilter,
        // },
    ],
})
export class AppModule implements NestModule {
    constructor() { }

    configure(consumer: MiddlewareConsumer) {
        // consumer
        //     .apply(LoggerMiddleware, reqMiddleware)
        //     .forRoutes('/user/*ist');
    }

    @OnEvent('user.create')
    handleUserCreateEvent(user) {
        console.log('user.create', 1111);
    }
}
